Seznam pocitacu v domene
Otázka od: petr polasek
6. 12. 2002 17:34
zdravim vsechny,
potreboval bych napsat funkci, ktera by me vracela nazvy vsech
pocitacu v domene. Server i stanice jsou pod windows 2000.
Pouzivam Delphi 5. predem dik za pomoc.
--
----
Vyhraj 2listky na Breakbeat Conference
7.12.2002 v Roxy. zacatek od 22:00
Soutez na http://web.volny.cz
Vice informaci o akci na www.lighthouse.cz
Odpovedá: petr polasek
12. 12. 2002 17:06
chtěl bych se ještě poradit ohledně toho seznamu pocitacu v
domene. pokud jako parametr zadam nazev nasi domeny,tak mi to
vrati netresult=2351, nevi nekdo co to znamena? Pokud tam je nil,
tak to vrati sice 0, ale stejne mi to vrati prazdny list.
potreboval bych napsat funkci, ktera by
me
vracela nazvy vsech
pocitacu v domene. Server i stanice jsou
pod windows 2000.
Pouzivam Delphi 5. predem dik za pomoc.
Je na to funkcia NetServerEnum, tu je
jednoduchy priklad:
const
NERR_SUCCESS = 0;
MAX_PREFERRED_LENGTH = -1;
SV_TYPE_WORKSTATION = 1;
SV_TYPE_SERVER = 2;
type
PServerInfo100 = ^TServerInfo100;
TServerInfo100 = packed record
sv100_platform_id: DWORD;
sv100_name: PWideChar;
end;
function NetServerEnum(servername:
PWideChar;
level: DWORD; var bufptr:
Pointer; prefmaxlen: DWORD;
var entriesread: DWORD; var totalentries:
DWORD; servertype: DWORD;
domain: PWideChar;
var resume_handle: DWORD): Integer;
stdcall;
external 'netapi32.dll';
function NetApiBufferFree(Buffer: Pointer):
Integer; stdcall; external
'netapi32.dll';
function GetDomainComputerNames(List:
TStrings): Boolean;
var
NetResult: Integer;
Buf: Pointer;
EntriesRead, TotalEntries, ResumeHandle:
Cardinal;
I: Integer;
P: PServerInfo100;
begin
Result := False;
EntriesRead := 0;
TotalEntries := 0;
ResumeHandle := 0;
NetResult := NetServerEnum(nil, 100, Buf,
Cardinal(MAX_PREFERRED_LENGTH),
EntriesRead, TotalEntries,
SV_TYPE_SERVER or SV_TYPE_WORKSTATION, nil,
ResumeHandle);
if NetResult = NERR_SUCCESS then
try
P := Buf;
for I := 0 to EntriesRead - 1 do
begin
List.Add(P^.sv100_name);
Inc(P);
end;
Result := True;
finally
NetApiBufferFree(Buf);
end;
end;
procedure TForm1.Button1Click(Sender:
TObject);
var
List: TStringList;
begin
List := TStringList.Create;
try
if GetDomainComputerNames(List) then
ShowMessage(List.Text);
finally
List.Free;
end;
end;
----- PŮVODNÍ ZPRÁVA -----
Od: "Robert Suska" <delphi@korak.sk>
Komu: delphi-l@clexpert.cz
Předmět: Re: RE: Seznam pocitacu v domene
Datum: 9.12.2002 - 14:32:01
> Ahojte!
>
> Aj mne to slape ako hodinky len este jedna
> vec by ma zaujimala ako zistit
> napr. zoznam domen a nejako to napasovat na
> tento kod a pekne keby som si
> vybral z comboboxu nazov domeny resp.
> workgroupy tak by sa mi ku nej
> zobrazil zoznam pc v tej domene
>
> Dakujem za nakopnutie
>
> Robo
>
>
> ************************************
> Robert Suska
> KORAK SLOVAKIA s.r.o.
> Horna 52
> 974 01 Banska Bystrica
> www.korak.sk robert@korak.sk
> Network administrator, Delphi programmer
> ************************************
>
>
>
> Zdravim
>
> Me tahle fce funguje naprosto bez jakychkoliv
> uprav a problemu.
>
> Zdenek
>
> -----Original Message-----
>
> Diky za pomoc, ale me to vraci prazdny list,
> pritom mam v domene asi 50
> pocitacu a 10 serveru. NetResult mi vraci
> NERR_SUCCESS, takze nevim v
> cem je problem. Jo a jeste funkce
> NetSessionEnum pres level 10 mi
> funguje uplne super na vsech serverech.
>
> ----- PŮVODNÍ ZPRÁVA -----
>
> > > potreboval bych napsat funkci, ktera by
> > > me
> > > vracela nazvy vsech
> > > pocitacu v domene. Server i stanice jsou
> > > pod windows 2000.
> > > Pouzivam Delphi 5. predem dik za pomoc.
> >
> > Je na to funkcia NetServerEnum, tu je
> > jednoduchy priklad:
> >
> > const
> > NERR_SUCCESS = 0;
> > MAX_PREFERRED_LENGTH = -1;
> >
> > SV_TYPE_WORKSTATION = 1;
> > SV_TYPE_SERVER = 2;
> >
> > type
> > PServerInfo100 = ^TServerInfo100;
> > TServerInfo100 = packed record
> > sv100_platform_id: DWORD;
> > sv100_name: PWideChar;
> > end;
> >
> > function NetServerEnum(servername:
> > PWideChar;
> > level: DWORD; var bufptr:
> > Pointer; prefmaxlen: DWORD;
> > var entriesread: DWORD; var totalentries:
> > DWORD; servertype: DWORD;
> > domain: PWideChar;
> > var resume_handle: DWORD): Integer;
> > stdcall;
> > external 'netapi32.dll';
> > function NetApiBufferFree(Buffer: Pointer):
> > Integer; stdcall; external
> > 'netapi32.dll';
> >
> > function GetDomainComputerNames(List:
> > TStrings): Boolean;
> > var
> > NetResult: Integer;
> > Buf: Pointer;
> > EntriesRead, TotalEntries, ResumeHandle:
> > Cardinal;
> > I: Integer;
> > P: PServerInfo100;
> > begin
> > Result := False;
> > EntriesRead := 0;
> > TotalEntries := 0;
> > ResumeHandle := 0;
> > NetResult := NetServerEnum(nil, 100, Buf,
> > Cardinal(MAX_PREFERRED_LENGTH),
> > EntriesRead, TotalEntries,
> > SV_TYPE_SERVER or SV_TYPE_WORKSTATION, nil,
> > ResumeHandle);
> > if NetResult = NERR_SUCCESS then
> > try
> > P := Buf;
> > for I := 0 to EntriesRead - 1 do
> > begin
> > List.Add(P^.sv100_name);
> > Inc(P);
> > end;
> > Result := True;
> > finally
> > NetApiBufferFree(Buf);
> > end;
> > end;
> >
> > procedure TForm1.Button1Click(Sender:
> > TObject);
> > var
> > List: TStringList;
> > begin
> > List := TStringList.Create;
> > try
> > if GetDomainComputerNames(List) then
> > ShowMessage(List.Text);
> > finally
> > List.Free;
> > end;
> > end;
>
>
--
---
Ales Brichta
Live 12.12. od 14:00 na
http://chat.volny.cz
Odpovedá: Ondrej Kelle
7. 12. 2002 11:18
> potreboval bych napsat funkci, ktera by me vracela nazvy vsech
> pocitacu v domene. Server i stanice jsou pod windows 2000.
> Pouzivam Delphi 5. predem dik za pomoc.
Je na to funkcia NetServerEnum, tu je jednoduchy priklad:
const
NERR_SUCCESS = 0;
MAX_PREFERRED_LENGTH = -1;
SV_TYPE_WORKSTATION = 1;
SV_TYPE_SERVER = 2;
type
PServerInfo100 = ^TServerInfo100;
TServerInfo100 = packed record
sv100_platform_id: DWORD;
sv100_name: PWideChar;
end;
function NetServerEnum(servername: PWideChar; level: DWORD; var bufptr:
Pointer; prefmaxlen: DWORD;
var entriesread: DWORD; var totalentries: DWORD; servertype: DWORD;
domain: PWideChar;
var resume_handle: DWORD): Integer; stdcall; external 'netapi32.dll';
function NetApiBufferFree(Buffer: Pointer): Integer; stdcall; external
'netapi32.dll';
function GetDomainComputerNames(List: TStrings): Boolean;
var
NetResult: Integer;
Buf: Pointer;
EntriesRead, TotalEntries, ResumeHandle: Cardinal;
I: Integer;
P: PServerInfo100;
begin
Result := False;
EntriesRead := 0;
TotalEntries := 0;
ResumeHandle := 0;
NetResult := NetServerEnum(nil, 100, Buf, Cardinal(MAX_PREFERRED_LENGTH),
EntriesRead, TotalEntries,
SV_TYPE_SERVER or SV_TYPE_WORKSTATION, nil, ResumeHandle);
if NetResult = NERR_SUCCESS then
try
P := Buf;
for I := 0 to EntriesRead - 1 do
begin
List.Add(P^.sv100_name);
Inc(P);
end;
Result := True;
finally
NetApiBufferFree(Buf);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
List: TStringList;
begin
List := TStringList.Create;
try
if GetDomainComputerNames(List) then
ShowMessage(List.Text);
finally
List.Free;
end;
end;
HTH
TOndrej